package com.pikaqiu.warehouse.controller;

import com.pikaqiu.warehouse.domain.common.MiniAjaxResult;
import com.pikaqiu.warehouse.domain.dto.CategoryDto;
import com.pikaqiu.warehouse.domain.req.CategoryForm;
import com.pikaqiu.warehouse.service.CategoryService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: Administrator
 * @Date: 2024/8/14
 */
@RestController
@RequestMapping("/category")
public class CategoryController {

    @Resource
    private CategoryService categoryService;

    @GetMapping("/list")
    public MiniAjaxResult<List<CategoryDto>> list(Integer type) {
        return MiniAjaxResult.success(categoryService.listByType(type));
    }

    @PostMapping("/save")
    public MiniAjaxResult<String> saveCategory(CategoryForm categoryForm) {
        categoryService.saveCategory(categoryForm);
        return MiniAjaxResult.success();
    }
}
